package gwt.immunology.shared.utils;

import java.text.ParseException;
import java.util.Date;

import com.google.gwt.i18n.shared.DateTimeFormat;
import com.google.gwt.user.client.Window;

public class ImmunologyUtils {
    
    public static final String DD_MM_YYYY = "dd-MM-yyyy";
    
    public static String getClientWindowFreeSpacePx() {
        return Window.getClientHeight() - 100 + "px";
    }
    
    public static boolean isDigit(String string) {
        return string.matches("\\d+");
    }
    
    /**
     * Method converts date to string.
     * 
     * @param date - date to be converted to string
     * @param pattern string, representing date format
     * @return java.lang.String
     */
    public static String convertDateToString(Date date, String pattern) {
        return DateTimeFormat.getFormat(pattern).format(date);
    }
    
    /**
     * Method converts string to date.
     * 
     * @param date string, representing date
     * @return java.util.Date
     */
    public static Date convertStringToDate(String date) {
        return DateTimeFormat.getFormat(DD_MM_YYYY).parse(date);
    }

}
